﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class System_Rule_DepartmentInfo
    {
                 #region /*Không thay đổi*/
        public bds m_bds = new bds();

        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
        #endregion /*Không thay đổi*/

        private DBMain m_data = new DBMain();
        #region [Properties - Thuộc tính]
        public System_Rule_Department Properties
        {
            get { return m_bds.Current as System_Rule_Department; }
        }
        #endregion

        public System_Rule_DepartmentInfo(Guid _guiUserKey, int _intDepartmentKey)
        {
            var Iquery = m_data.m_DCSave.System_Rule_Departments.Where(p => p.System_UserKey == _guiUserKey && p.Catalogue_DepartmentKey == _intDepartmentKey);
             m_bds.DataSource = Iquery;
             var Row = Iquery.FirstOrDefault();
             if (Row == null)
             {
                 System_Rule_Department srd = new System_Rule_Department();
                 srd.Catalogue_DepartmentKey = _intDepartmentKey;
                 srd.System_UserKey = _guiUserKey;
                 Row = srd;
                 m_bds.Add(Row);
                 m_bds.MoveLast();
             }
        }

        public void Delete()
        {
            m_bds.DeleteCurrent();
        }
    }
}
